package aufgabe8;

import java.util.*;
import java.io.*;

public class DatenLesen
{
  public static double[] liesDaten(String filename)
  {
    File f = new File(filename);
    Scanner sc = null;
    try
    {
      sc = new Scanner(f);
    }
    catch (FileNotFoundException e)
    {
      System.out.println("File not found.");
      System.exit(0);
    }
    String content = "";
    while(sc.hasNextLine())
      content += sc.nextLine()+"\n";
    sc.close();
    
    int n = 0;
    double[] values = new double[n];
    String[] lines = content.split("\n");
    for(String line : lines)
    {
      if(n > 0)
      {
        values[values.length-n] = Double.parseDouble(line.trim());
        n--;
      }
      if(line.contains("Anzahl der Messdaten:") && !line.startsWith("#"))
      {
        n = Integer.parseInt(line.split(":")[1].trim());
        
        values = new double[n];        
      }
    }
    return values;
  }
  public static void main(String[] args)
  {
    double[] values = liesDaten("V:/Eclipse Workspace/Probeklausur Java April 2010/src/aufgabe8/messdaten.txt");
    for(double value : values)
    {
      System.out.println(value);
    }
  }
}
